<template>
  <div id="recruitTable">
    <el-dialog title="退回原因" :visible.sync="backFormVisible" :close-on-click-modal="false" width="700px" :close-on-press-escape="false">
      <el-form :model="backForm" ref="backForm" :inline="true" inline-message>
        <el-form-item prop="remark">
          <el-input v-model="backForm.remark" style="width:600px"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click.native="setState(canAudit?5:6,stepBatchId)" :loading="btnLoading">提交</el-button>
        <el-button @click.native="backFormVisible = false">取消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="备注" :visible.sync="remarksVisible" :close-on-click-modal="false" width="700px" :close-on-press-escape="false">
      <el-form :model="remarksForm" ref="remarksForm" :inline="true" inline-message>
        <el-form-item prop="remarks">
          <el-input v-model="remarksForm.remarks" style="width:600px"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click.native="setRemarks(remarksId)" :loading="btnLoading">提交</el-button>
        <el-button @click.native="remarksVisible = false">取消</el-button>
      </div>
    </el-dialog>
    <div v-if="state===5||state===6" style="margin-bottom:10px;font-weight:bolder">状态：已退回  退回原因：{{remarks?remarks:'无'}}</div>

    <div v-if="!fileListLoading">
      <template v-if="announcementRemarks||(files1&&files1.length>0)">
        <h1>招聘公告参考材料</h1>
      </template>
      <template v-if="announcementRemarks">
        <div style="line-height: 150%;" v-html="announcementRemarks.replace(/\n/g,'<br>')"></div>
      </template>
      <template v-if="files1&&files1.length>0">
        <div v-for="(item,index) in files1" :key="index" style="line-height:40px">
          <a href="javascript:void(0)" @click="download(item.id)"><i class="el-icon-paperclip" /> {{item.fileName}}.{{item.fileType}}</a>
          <!-- <template v-if="item.fileType==='pdf'"><i style="cursor: pointer;" class="el-icon-search" @click="showfile(item.id)" /></template> -->
        </div>
      </template>
    </div>
    <div v-else>加载中...</div>
    <h1 style="text-align:center">{{theYear}}年度招聘岗位</h1>
    <el-table :data="postList" highlight-current-row v-loading="listLoading4" style="width: 100%;margin-bottom: 20px;" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" :selectable="canSelect" v-if="userType===1">
      </el-table-column>
      <el-table-column type="index" label="序号" width="60" align="center">
      </el-table-column>
      <el-table-column prop="theType" label="岗位类型" width="150" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.theType===1">应届毕业生招聘</span>
          <span v-else>在职人员招聘</span>
        </template>
      </el-table-column>
      <el-table-column prop="unitName" label="单位名称" min-width="150" header-align="center">
        <template slot-scope="scope">
          {{scope.row.unitName}}（{{scope.row.unitBeijing===1?"在京单位":"京外单位"}}）
        </template>
      </el-table-column>
      <el-table-column prop="inBeijing" label="生源类型" width="100" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.inBeijing===1">京内生源</span>
          <span v-if="scope.row.inBeijing===2">京外生源</span>
        </template>
      </el-table-column>
      <el-table-column prop="department" label="具体工作部门" width="250" header-align="center">
      </el-table-column>
      <el-table-column prop="post" label="岗位" width="150" header-align="center">
      </el-table-column>
      <el-table-column prop="major" label="专业" width="250" header-align="center">
      </el-table-column>
      <el-table-column prop="education" label="学历要求" width="120" align="center">
      </el-table-column>
      <el-table-column v-if="step==='bus_candidate_announcement'" prop="realName" label="姓名" width="80" align="center">
      </el-table-column>
      <el-table-column v-if="step==='bus_candidate_announcement'" prop="idCardNo" label="身份证号" width="200" align="center">
      </el-table-column>
      <el-table-column v-if="step==='bus_candidate_announcement'" prop="personState" label="确认拟聘人选" width="120" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.personState===0">未确认</span>
          <span v-else-if="scope.row.personState===1||scope.row.personState===2" style="color:green;font-weight:bolder">已确认</span>
          <span v-else-if="scope.row.personState===5" style="color:red;font-weight:bolder">已退回</span>
        </template>
      </el-table-column>
      <el-table-column prop="stepState" label="状态" width="110" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.stepState===0">未提交</span>
          <span v-else-if="scope.row.stepState===1" style="color:orange;font-weight:bolder">待预审</span>
          <span v-else-if="scope.row.stepState===2" style="color:blue;font-weight:bolder">待终审</span>
          <span v-else-if="scope.row.stepState===3" style="color:blue;font-weight:bolder">待发布</span>
          <span v-else-if="scope.row.stepState===4" style="color:green;font-weight:bolder">已发布</span>
          <span v-else-if="scope.row.stepState===5" style="color:red;font-weight:bolder">预审退回</span>
          <span v-else-if="scope.row.stepState===6" style="color:red;font-weight:bolder">终审退回</span>
        </template>
      </el-table-column>
    </el-table>
    <!-- <div v-if="canEdit">
      <el-upload
        style="width:800px;margin-bottom:10px;"
        ref="upload"
        :action="this.$http.defaults.baseURL+this.$http.defaults.recruitAPI +'api/recruitGenFileInfo/upload'"
        :on-success="handleUploadSucc1"
        :on-error="uploadError"
        :before-upload="beforeUpload"
        accept="application/pdf"
        :show-file-list="false"
      >
        <el-button type="primary" :loading="saveloading">{{step==='bus_announcement'?'上传招聘公告文件':'上传拟聘人选公示文件'}}</el-button>
      </el-upload>
    </div>
    <div v-if="!fileListLoading">
      <template v-if="files&&files.length>0">
        <div v-for="(item,index) in files" :key="index" style="line-height:40px">
          <a href="javascript:void(0)" @click="download(item.id)"><i class="el-icon-paperclip" /> {{item.fileName}}.{{item.fileType}}</a>
          <el-button v-if="canEdit" style="margin-left:10px" size="mini" type="danger" @click="beforeRemove(item,step,'files')">删除</el-button>
        </div>
      </template>
    </div>
    <div v-else>加载中...</div> -->
    <template>
      <el-button icon="el-icon-s-promotion" type="success" style="margin-bottom:20px" @click="setState(0)" v-if="canEdit" :loading='btnLoading'>打捆</el-button>
    </template>
    <template>
      <h1 style="text-align:center">批次列表</h1>
      <el-table :data="batchList" highlight-current-row v-loading="listLoading" style="width: 100%;margin-bottom: 20px;">
        <el-table-column prop="state" label="状态" width="120" align="center">
          <template slot-scope="scope">
            <el-tooltip v-if="scope.row.state===5" class="item" effect="dark" :content="'退回时间：'+scope.row.backTime+ ' 退回原因：'+scope.row.remarks" placement="top" :open-delay="500">
              <el-tag effect="dark" type="danger" style="cursor: pointer;">预审退回</el-tag>
            </el-tooltip>
            <el-tooltip v-if="scope.row.state===6" class="item" effect="dark" :content="'退回时间：'+scope.row.backTime+ ' 退回原因：'+scope.row.remarks" placement="top" :open-delay="500">
              <el-tag effect="dark" type="danger" style="cursor: pointer;">终审退回</el-tag>
            </el-tooltip>
            <el-tooltip v-if="scope.row.state===1" class="item" effect="dark" :content="'提交时间：'+scope.row.submitTime" placement="top" :open-delay="500">
              <el-tag effect="dark" type="warning" style="cursor: pointer;">待预审</el-tag>
            </el-tooltip>
            <el-tooltip v-if="scope.row.state===2" class="item" effect="dark" :content="'提交时间：'+scope.row.submitTime" placement="top" :open-delay="500">
              <el-tag effect="dark" style="cursor: pointer;">待终审</el-tag>
            </el-tooltip>
            <el-tooltip v-if="scope.row.state===3" class="item" effect="dark" :content="'提交时间：'+scope.row.submitTime" placement="top" :open-delay="500">
              <el-tag effect="dark" style="cursor: pointer;">待发布</el-tag>
            </el-tooltip>
            <el-tooltip v-if="scope.row.state===4" class="item" effect="dark" :content="'提交时间：'+scope.row.submitTime" placement="top" :open-delay="500">
              <el-tag effect="dark" type="success" style="cursor: pointer;">已发布</el-tag>
            </el-tooltip>
            <el-tag v-if="scope.row.state===0" effect="dark">未提交</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="num" label="岗位数量" width="100" align="center">
          <template slot-scope="scope">
            <el-popover placement="right" trigger="hover" :open-delay="500">
              <div class="recruitTable">
                <el-table :data="scope.row.postDocking" border>
                  <el-table-column prop="theType" label="岗位类型" width="150" align="center">
                    <template slot-scope="scope">
                      <span v-if="scope.row.theType===1">应届毕业生招聘</span>
                      <span v-else>在职人员招聘</span>
                    </template>
                  </el-table-column>
                  <el-table-column prop="unitName" label="单位名称" width="250" header-align="center">
                    <template slot-scope="scope">
                      {{scope.row.unitName}}（{{scope.row.unitBeijing===1?"在京单位":"京外单位"}}）
                    </template>
                  </el-table-column>
                  <el-table-column prop="inBeijing" label="生源类型" width="100" align="center">
                    <template slot-scope="scope">
                      <span v-if="scope.row.inBeijing===1">京内生源</span>
                      <span v-if="scope.row.inBeijing===2">京外生源</span>
                    </template>
                  </el-table-column>
                  <el-table-column prop="department" label="具体工作部门" width="250" header-align="center">
                  </el-table-column>
                  <el-table-column prop="post" label="岗位" width="150" header-align="center">
                  </el-table-column>
                  <el-table-column prop="major" label="专业" width="250" header-align="center">
                  </el-table-column>
                  <el-table-column prop="education" label="学历要求" width="150" align="center">
                  </el-table-column>
                </el-table>
              </div>
              <el-button slot="reference" type="text" icon="el-icon-search">{{scope.row.postDocking.length}}</el-button>
            </el-popover>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="files" :label="step==='bus_announcement'?'招聘公告文件':'拟聘人选公示文件'" min-width="150">
          <template slot-scope="scope">
            <div v-if="canEdit&&(scope.row.state===5||scope.row.state===6||scope.row.state===0)">
              <el-upload
                style="width:800px;margin-bottom:10px;"
                ref="upload"
                :action="$http.defaults.baseURL+$http.defaults.recruitAPI +'api/recruitGenFileInfo/upload'"
                :on-success="function (res, file) { return handleUploadSucc1(res, file, scope.row.id)}"
                :on-error="uploadError"
                :before-upload="beforeUpload"
                accept="application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-works,.wps"
                :show-file-list="false"
              >
                <el-button type="primary" size="small" :loading="saveloading">上传</el-button>
              </el-upload>
            </div>
            <template v-if="scope.row.files&&scope.row.files.length>0">
              <div v-for="(item,index) in scope.row.files.filter(item=>!item.businessStep)" :key="index" style="line-height:40px">
                <a href="javascript:void(0)" @click="download(item.id)"><i class="el-icon-paperclip" /> {{item.fileName}}.{{item.fileType}}</a>
                <el-button v-if="canEdit&&(scope.row.state===5||scope.row.state===6||scope.row.state===0)" :loading="listLoading" style="margin-left:10px" size="mini" type="danger" @click="beforeRemove(item,step,'files')">删除</el-button>
              </div>
            </template>
          </template>
        </el-table-column> -->
        <el-table-column prop="files" label="正式文件（仅人事司可见）" min-width="150" v-if="canBack">
          <template slot-scope="scope">
            <template v-if="canBack">
              <el-upload
                v-if="scope.row.state>=2"
                style="width:800px;margin-bottom:10px;"
                :action="$http.defaults.baseURL+$http.defaults.recruitAPI +'api/recruitGenFileInfo/upload'"
                :on-success="function (res, file) { return getImportList2(res, file, scope.row.id,'step2')}"
                :on-error="uploadError"
                :before-upload="beforeUpload"
                accept="application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-works,.wps"
                with-credentials
                :show-file-list="false"
                >
                <el-button type="primary" :loading="saveloading">上传</el-button>
              </el-upload>
              <div v-if="!fileListLoading">
                <template v-if="scope.row.files&&scope.row.files.length>0">
                  <div v-for="(item,index) in scope.row.files.filter(item=>item.businessStep==='step2')" :key="index" style="line-height:40px">
                    <a href="javascript:void(0)" @click="download(item.id)"><i class="el-icon-paperclip" /> {{item.fileName}}.{{item.fileType}}</a>
                    <el-button v-if="scope.row.state===2" style="margin-left:10px" size="mini" type="danger" @click="beforeRemove(item,step)">删除</el-button>
                  </div>
                </template>
              </div>
              <div v-else>加载中...</div>
            </template>
            <template v-else-if="!canBack&&(scope.row.state===3||scope.row.state===4)">
              <div v-if="!fileListLoading">
                <template v-if="scope.row.files2&&scope.row.files.length>0">
                  <div v-for="(item,index) in scope.row.files.filter(item=>item.businessStep==='step2')" :key="index" style="line-height:40px">
                    <a href="javascript:void(0)" @click="download(item.id)"><i class="el-icon-paperclip" /> {{item.fileName}}.{{item.fileType}}</a>
                  </div>
                </template>
              </div>
              <div v-else>加载中...</div>
            </template>
            <!-- <template v-if="scope.row.files&&scope.row.files.length>0">
              <div v-for="(item,index) in scope.row.files" :key="index" style="line-height:40px">
                <a href="javascript:void(0)" @click="download(item.id)"><i class="el-icon-paperclip" /> {{item.fileName}}.{{item.fileType}}</a>
              </div>
            </template> -->
          </template>
        </el-table-column>
        <el-table-column prop="remarks" label="备注（仅人事司可见）" min-width="150" v-if="canBack">
          <template slot-scope="scope">
            <template v-if="canBack">
              {{scope.row.remarks}}
              <el-button @click="editRemarks(scope.row)" type="text" icon="el-icon-edit"></el-button>
            </template>
          </template>
        </el-table-column>
        <el-table-column prop="audit1" key="audit1" label="预审" min-width="150" v-if="userType===2||userType===3" align="center">
          <template slot-scope="scope">
            <template v-if="canAudit&&(scope.row.state===1||scope.row.state===2||scope.row.state===6)">
              <el-button :loading="btnLoading" v-if="scope.row.state===1||scope.row.state===6" icon="el-icon-s-claim" type="success" @click="setState(2,scope.row.id)">完成</el-button>
              <el-button v-if="scope.row.state===1||scope.row.state===6" icon="el-icon-s-release" type="danger" @click="showBack(scope.row.id)">退回</el-button>
              <el-button :loading="btnLoading" v-if="scope.row.state===2" icon="el-icon-back" type="danger" @click="setState(1,scope.row.id,'back')">撤回</el-button>
            </template>
            <template v-else>
              <b v-if="scope.row.state===2||scope.row.state===3||scope.row.state===4" style="color:green">已完成</b>
              <span v-else>未完成</span>
            </template>
          </template>
        </el-table-column>
        <el-table-column prop="audit2" key="audit2" label="终审（人事司已向人社部发函）" min-width="150" v-if="userType===2||userType===3" align="center">
          <template slot-scope="scope">
            <template v-if="canBack&&scope.row.state<4&&scope.row.state>1">
              <el-button :loading="btnLoading" v-if="scope.row.state===2" icon="el-icon-s-claim" type="success" @click="setState(3,scope.row.id)">完成</el-button>
              <el-button v-if="scope.row.state===2" icon="el-icon-s-release" type="danger" @click="showBack(scope.row.id)">退回</el-button>
              <el-button :loading="btnLoading" v-if="scope.row.state===3" icon="el-icon-back" type="danger" @click="setState(2,scope.row.id,'back')">撤回</el-button>
            </template>
            <template v-else>
              <b v-if="scope.row.state===3||scope.row.state===4" style="color:green">已完成</b>
              <span v-else>未完成</span>
            </template>
          </template>
        </el-table-column>
        <!--<el-table-column prop="remarks" label="初审" v-if="userType===2||userType===3" align="center">
          <el-table-column prop="remarks" label="人力中心已向人社部提交电子版材料" width="150" align="center">
            <template slot-scope="scope">
              <template v-if="canAudit">
                <template v-if="scope.row.state===3">
                  <el-button v-if="!scope.row.flag1" @click="setFlag(scope.row.id)" type="primary" :loading="btnLoading">完成</el-button>
                  <b style="color:green" v-else>已完成</b>
                </template>
                <template v-if="scope.row.state!==3">
                  <span v-if="!scope.row.flag1">未完成</span>
                  <b style="color:green" v-else>已完成</b>
                </template>
              </template>
              <template v-else>
                <b v-if="scope.row.flag1" style="color:green">已完成</b>
                <span v-else>未完成</span>
              </template>
            </template>
          </el-table-column>
          <el-table-column prop="remarks" label="人事司已向人社部发函" width="150" align="center">
            <template slot-scope="scope">
              <template v-if="canBack">
                <template v-if="scope.row.state===3">
                  <el-button v-if="!scope.row.flag2" @click="setFlag(scope.row.id)" type="primary" :loading="btnLoading">完成</el-button>
                  <b style="color:green" v-else>已完成</b>
                </template>
                <template v-else>
                  <span v-if="!scope.row.flag2">未完成</span>
                  <b style="color:green" v-else>已完成</b>
                </template>
              </template>
              <template v-else>
                <b v-if="scope.row.flag2" style="color:green">已完成</b>
                <span v-else>未完成</span>
              </template>
            </template>
          </el-table-column>
        </el-table-column> -->
        <!-- <el-table-column prop="files" label="人社部网站信息、截图" min-width="150">
          <template slot-scope="scope">
            <template v-if="canBack">
              <el-upload v-if="scope.row.state===3"
                style="width:800px;margin-bottom:10px;"
                :action="$http.defaults.baseURL+$http.defaults.recruitAPI +'api/recruitGenFileInfo/upload'"
                :on-success="function (res, file) { return getImportList2(res, file, scope.row.id,'step3')}"
                :on-error="uploadError"
                :before-upload="beforeUpload"
                accept="application/pdf"
                with-credentials
                :show-file-list="false"
                >
                <el-button type="primary" :loading="saveloading">上传</el-button>
              </el-upload>
              <div v-if="!fileListLoading">
                <template v-if="scope.row.files&&scope.row.files.length>0">
                  <div v-for="(item,index) in scope.row.files.filter(item=>item.businessStep==='step3')" :key="index" style="line-height:40px">
                    <a href="javascript:void(0)" @click="download(item.id)"><i class="el-icon-paperclip" /> {{item.fileName}}.{{item.fileType}}</a>
                    <el-button v-if="scope.row.state===3" style="margin-left:10px" size="mini" type="danger" @click="beforeRemove(item,step)" :loading="listLoading">删除</el-button>
                  </div>
                </template>
              </div>
              <div v-else>加载中...</div>
            </template>
            <template v-else-if="!canBack&&(scope.row.state===4)">
              <div v-if="!fileListLoading">
                <template v-if="scope.row.files2&&scope.row.files.length>0">
                  <div v-for="(item,index) in scope.row.files.filter(item=>item.businessStep==='step3')" :key="index" style="line-height:40px">
                    <a href="javascript:void(0)" @click="download(item.id)"><i class="el-icon-paperclip" /> {{item.fileName}}.{{item.fileType}}</a>
                  </div>
                </template>
              </div>
              <div v-else>加载中...</div>
            </template>
          </template>
        </el-table-column> -->
        <el-table-column :label="'已发布'+(step==='bus_announcement'?'公告':'公示')" min-width="150" key="audit3" v-if="userType===2||userType===3" align="center">
          <template slot-scope="scope">
            <template v-if="canAudit&&scope.row.state>2&&scope.row.state<5">
              <el-button :loading="btnLoading" v-if="scope.row.state===3" icon="el-icon-s-claim" type="success" @click="setState(4,scope.row.id)">完成</el-button>
              <el-button :loading="btnLoading" v-if="scope.row.state===4" icon="el-icon-back" type="danger" @click="setState(3,scope.row.id,'back')">撤回</el-button>
            </template>
            <template v-else>
              <b v-if="scope.row.state===4" style="color:green">已完成</b>
              <span v-else>未完成</span>
            </template>
            <!-- <el-button :loading="btnLoading" v-if="canAudit&&scope.row.state===3&&scope.row.flag1&&scope.row.flag2" icon="el-icon-s-claim" type="success" @click="setState(4,scope.row.id)">发布{{step==='bus_announcement'?'公告':'公示'}}</el-button> -->
            <!-- <el-button :loading="btnLoading" v-if="canAudit&&scope.row.state===4" icon="el-icon-s-release" type="danger" @click="setState(7,scope.row.id)">撤回发布</el-button> -->
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="300" key="detail" v-if="userType===1">
          <template slot-scope="scope">
            <el-button v-if="canEdit&&(scope.row.state===5||scope.row.state===0)" :loading="btnLoading" @click="setState(1,scope.row.id)" size="small" type="success">提交</el-button>
            <el-button :loading="listLoading" v-if="canEdit&&(scope.row.state===0||scope.row.state===5)" @click="removeBatch(scope.row.id)" size="small" type="danger">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>
  </div>
</template>
<script>
export default {
  props: {
    step: '',
    timestamp: '',
    userType: null,
    unitId: null,
    type: null,
    theYear: null,
    unitBeijing: null
  },
  watch: {
    step (val) {
      console.log(val)
    },
    userType (val) {
      console.log(val)
    },
    timestamp (val) {
      if (this.userType === 1) {
        this.canEdit = true
      } else {
        this.canEdit = false
      }
      if (this.userType === 2) {
        this.canBack = true
      } else {
        this.canBack = false
      }
      if (this.userType === 3) {
        this.canAudit = true
      } else {
        this.canAudit = false
      }
      this.getPostListOtherStep()
      this.getStepBatch()
    },
    type (val) {
      console.log(val)
    },
    unitId (val) {
      console.log(val)
    },
    theYear (val) {
      console.log(val)
      if (this.step === 'bus_announcement') {
        this.getFileList()
        this.getAnnouncementRemarks()
      }
    },
    unitBeijing (val) {
      console.log(val)
    },
    batchState (val) {
      console.log(val)
    }
  },
  data () {
    return {
      remarksId: null,
      remarksForm: {remarks: ''},
      remarksVisible: false,
      canAudit: null,
      personId: null,
      personLoading: false,
      personList: [],
      remarks: null,
      listLoading1: false,
      listLoading2: false,
      listLoading3: false,
      listLoading4: false,
      state: null,
      canEdit: false,
      canBack: false,
      dialogEdit: 0,
      batchList: [
        // {unitName: '111', beijing: '京内', num: 2, state: 0},
        // {unitName: '111', beijing: '京内', num: 2, state: 1}
      ],
      postList: [
        // {unitName: '111(京内)', theTypeId: 1, theType: '应届毕业生招聘', beijing: '京内', education: '大专', state: 0, department: '财务处', post: '出纳', major: '会计学', times: 0},
        // {unitName: '111(京内)', theTypeId: 1, theType: '应届毕业生招聘', beijing: '京内', education: '本科生', state: 1, department: '财务处', post: '出纳', major: '会计学', realName: '张三', idCardNo: '131002198801021234', times: 1},
        // {unitName: '111(京内)', theTypeId: 1, theType: '应届毕业生招聘', beijing: '京内', education: '本科生', state: 2, department: '办公室', post: '文员', major: '汉语言', realName: '测试', idCardNo: '132801198201034231', times: 2},
        // {unitName: '111(京内)', theTypeId: 2, theType: '在职招聘', beijing: '京外', department: '信息中心', post: '科员', major: '计算机', education: '硕士研究生', state: 0, realName: '111', idCardNo: '133012198811124123', times: 1},
        // {unitName: '111(京内)', theTypeId: 2, theType: '在职招聘', beijing: '京外', education: '其他', state: 0, department: '办公室', post: '文员', major: '汉语言', times: 0}
      ],
      dialogTitle: '',
      // 专业类别未补全、民族未补全
      typeList: [{label: '应届毕业生招聘', value: 2}, {label: '在职人员招聘', value: 1}],
      sexList: [{label: '男', value: 1}, {label: '女', value: 0}],
      maritalStatusList: ['未婚', '已婚', '离婚', '丧偶'],
      degreeList: ['博士', '硕士', '学士', '其他'],
      educationList: ['大专', '本科生', '硕士研究生', '博士研究生', '其他'],
      recruitmentMethodList: [{label: '考试', value: 1}, {label: '引进', value: 2}],
      editLoading: false,
      backForm: {remark: ''},
      backFormVisible: false,
      fileListLoading: false,
      btnLoading: false,
      saveloading: false,
      files: [],
      listLoading: false,
      multipleSelection: [],
      stepBatchId: null,
      files1: [],
      announcementRemarks: ''
    }
  },
  methods: {
    setFlag (id) {
      let para = {
        id: id
      }
      if (this.canAudit) {
        para.flag1 = 1
      }
      if (this.canBack) {
        para.flag2 = 1
      }
      this.btnLoading = true
      this.$http.post(this.$http.defaults.recruitAPI + `api/recruitBusPostStepBatch/save`, para).then(response => {
        this.btnLoading = false
        if (response.data.success === true) {
          this.$message({
            message: '已完成',
            type: 'success'
          })
          this.remarksVisible = false
          this.getStepBatch()
        } else {
          console.log('完成失败:' + response.data.message)
          this.$message({
            message: '完成失败:' + response.data.message,
            type: 'error'
          })
        }
      }).catch(error => {
        this.btnLoading = false
        console.log(error)
        this.$message({
          message: '保存失败:' + error,
          type: 'error'
        })
      })
    },
    editRemarks (obj) {
      this.remarksForm.remarks = obj.remarks
      this.remarksId = obj.id
      this.remarksVisible = true
    },
    setRemarks () {
      let para = {
        id: this.remarksId,
        remarks: this.remarksForm.remarks
      }
      this.btnLoading = true
      this.$http.post(this.$http.defaults.recruitAPI + `api/recruitBusPostStepBatch/save`, para).then(response => {
        this.btnLoading = false
        if (response.data.success === true) {
          this.$message({
            message: '保存成功',
            type: 'success'
          })
          this.remarksVisible = false
          this.getStepBatch()
        } else {
          console.log('保存失败:' + response.data.message)
          this.$message({
            message: '保存失败:' + response.data.message,
            type: 'error'
          })
        }
      }).catch(error => {
        this.btnLoading = false
        console.log(error)
        this.$message({
          message: '保存失败:' + error,
          type: 'error'
        })
      })
    },
    getImportList2 (response, file, id, step) {
      if (response.success) {
        let para = {
          id: response.result[0].id,
          businessTable: 'bus_post_step_batch',
          businessId: id,
          businessStep: step,
          theYear: this.theYear
        }
        this.$http.post(this.$http.defaults.recruitAPI + `api/recruitGenFileInfo/save`, para).then(res => {
          this.saveloading = false
          if (res.data.success === true) {
            this.$message({
              message: '上传成功！',
              type: 'success'
            })
            this.getStepBatch()
            // this.batchList[index].files2.push(res.result[0])
          } else {
            console.log('上传失败:' + res.data.message)
            this.$message({
              message: '上传失败:' + res.data.message,
              type: 'error'
            })
          }
        })
          .catch(error => {
            this.saveloading = false
            console.log(error)
            this.$message({
              message: '上传失败:' + error,
              type: 'error'
            })
          })
      } else {
        this.saveloading = false
        this.$message({
          message: '上传失败:' + response.message,
          type: 'error'
        })
      }
    },
    removeBatch (id) {
      this.$confirm('确认删除该批次吗?', '提示', {
        type: 'warning'
      }).then(() => {
        let para = {ids: [id]}
        this.listLoading = true
        this.$http.post(this.$http.defaults.recruitAPI + 'api/recruitBusPostStepBatch/remove', para).then(response => {
          this.listLoading = false
          if (response.data.success === true) {
            this.$message({
              message: '删除成功',
              type: 'success'
            })
            this.getStepBatch()
            this.getPostListOtherStep()
          } else {
            console.log('删除失败:' + response.data.message)
            this.$message({
              message: '删除失败:' + response.data.message,
              type: 'error'
            })
          }
        })
          .catch(error => {
            this.listLoading = false
            console.log(error)
            this.$message({
              message: '删除失败:' + error,
              type: 'error'
            })
          })
      })
    },
    handleSelectionChange (val) {
      this.multipleSelection = val
    },
    getPostListOtherStep () {
      let para = {
        'step': this.step,
        'theYear': this.theYear,
        'unitId': this.unitId,
        deduct: 2
      }
      this.listLoading4 = true
      this.$http.post(this.$http.defaults.recruitAPI + `api/recruitBusPost/queryList`, para).then(response => {
        this.listLoading4 = false
        if (response.data.success === true) {
          this.postList = response.data.result
        } else {
          console.log('获取失败:' + response.data.message)
          this.$message({
            message: '获取失败:' + response.data.message,
            type: 'error'
          })
        }
      }).catch(error => {
        this.listLoading4 = false
        console.log(error)
        this.$message({
          message: '获取失败:' + error,
          type: 'error'
        })
      })
    },
    getStepBatch () {
      let para = {
        'pageNum': 1,
        'pageSize': 10000,
        'step': this.step,
        'theYear': this.theYear,
        'unitId': this.unitId
      }
      if (this.userType !== 1) {
        para.isAdmin = true
      }
      this.listLoading = true
      this.$http.post(this.$http.defaults.recruitAPI + `api/recruitBusPostStepBatch/queryByPage`, para).then(response => {
        this.listLoading = false
        if (response.data.success === true) {
          this.batchList = response.data.result.records
        } else {
          console.log('获取当前环节状态失败:' + response.data.message)
          this.$message({
            message: '获取当前环节状态失败:' + response.data.message,
            type: 'error'
          })
        }
      }).catch(error => {
        this.listLoading = false
        console.log(error)
        this.$message({
          message: '获取当前环节状态失败:' + error,
          type: 'error'
        })
      })
    },
    canSelect (row) {
      if (this.step === 'bus_announcement') {
        return true
      } else {
        if (row.personState === 1 || row.personState === 2) {
          return true
        } else {
          return false
        }
      }
    },
    showBack (id) {
      this.stepBatchId = id
      this.backFormVisible = true
      this.backForm.remark = ''
    },
    beforeUpload (file) {
      console.log('文件类型')
      console.log(file.name)
      const isFormat = file.name.indexOf('.docx') > 0 || file.name.indexOf('.doc') > 0 || file.name.indexOf('.pdf') > 0 || file.name.indexOf('.DOCX') > 0 || file.name.indexOf('.DOC') > 0 || file.name.indexOf('.PDF') > 0 || file.name.indexOf('.wps') > 0 || file.name.indexOf('.WPS') > 0
      const isLt500M = file.size / 1024 / 1024 < 60
      if (!isLt500M) {
        this.$message.error('单个附件不能超过60M!')
      } else {
        if (!isFormat) {
          this.$message.error('附件格式必须为word、pdf、wps!')
        } else {
          this.saveloading = true
        }
      }
      return isFormat && isLt500M
    },
    async handleUploadSucc1 (response, file, stepBatchId) {
      this.uploadSuccCommon(response, file, stepBatchId, this.step, 'files')
    },
    uploadSuccCommon (response, file, stepBatchId) {
      if (response.success) {
        let para = {
          id: response.result[0].id,
          businessTable: 'bus_post_step_batch',
          businessId: stepBatchId,
          theYear: this.theYear
        }
        this.$http.post(this.$http.defaults.recruitAPI + `api/recruitGenFileInfo/save`, para).then(res => {
          this.saveloading = false
          if (res.data.success === true) {
            this.$message({
              message: '上传成功！',
              type: 'success'
            })
            this.getStepBatch()
          } else {
            console.log('上传失败:' + res.data.message)
            this.$message({
              message: '上传失败:' + res.data.message,
              type: 'error'
            })
          }
        })
          .catch(error => {
            this.saveloading = false
            console.log(error)
            this.$message({
              message: '上传失败:' + error,
              type: 'error'
            })
          })
      } else {
        this.saveloading = false
        this.$message({
          message: '上传失败:' + response.message,
          type: 'error'
        })
      }
    },
    beforeRemove (file) {
      this.$confirm('确定删除' + file.fileName + '.' + file.fileType + '？', '提示', {
        type: 'warning'
      }).then(() => {
        this.handleRemove(file.id)
      })
    },
    handleRemove (id) {
      const url = 'api/recruitGenFileInfo/remove?id=' + id
      this.listLoading = true
      this.$http.get(this.$http.defaults.recruitAPI + url).then(res => {
        console.log('删除成功:', res)
        this.listLoading = false
        if (res.data.success === true) {
          this.getStepBatch()
          this.$message({
            message: '删除成功！',
            type: 'success'
          })
        }
      })
    },
    uploadError (err) {
      this.saveloading = false
      console.log(err)
      this.$message({
        message: '上传失败:' + err,
        type: 'error'
      })
    },
    download (id) {
      window.open(this.$http.defaults.baseURL + this.$http.defaults.recruitAPI + 'api/recruitGenFileInfo/download?id=' + id)
    },
    getFileList () {
      this.fileListLoading = true
      this.$http.get(this.$http.defaults.recruitAPI + `api/recruitBusAnnual/getFileListByYear?theYear=${this.theYear}`).then(response => {
        this.fileListLoading = false
        if (response.data.success === true) {
          this.files1 = response.data.result
        } else {
          console.log('获取失败:' + response.data.message)
          this.$message({
            message: '获取失败:' + response.data.message,
            type: 'error'
          })
        }
      }).catch(error => {
        console.log(error)
        this.$message({
          message: '网络获取失败:' + error,
          type: 'error'
        })
        this.fileListLoading = false
      })
    },
    setState (state, stepBatchId, flag) {
      let stateText = ''
      switch (state) {
        case 0:
          stateText = '打捆'
          break
        case 1:
          stateText = '提交'
          break
        case 2:
          stateText = '完成'
          break
        case 3:
          stateText = '完成'
          break
        case 4:
          stateText = '完成'
          break
        case 5:
          stateText = '退回'
          break
        case 6:
          stateText = '退回'
          break
        case 7:
          stateText = '发布撤回'
          state = 3
          break
      }
      if (flag === 'back') {
        stateText = '撤回'
      }
      this.$confirm('确认' + stateText + '吗?', '提示', {
        type: 'warning'
      }).then(() => {
        let para = {
          state: state,
          theYear: this.theYear,
          step: this.step,
          id: stepBatchId
        }
        if (state === 5 || state === 6) {
          para.remarks = this.backForm.remark
        }
        if (state === 0 && this.step !== 'bus_post_docking' && this.step !== 'bus_plan_release' && this.step !== 'bus_plan_declare') {
          if (this.multipleSelection && this.multipleSelection.length > 0) {
            para.postDockingIds = ',' + this.multipleSelection.map(item => item.id).join(',') + ','
            para.fileIds = this.files.map(item => item.id)
          } else {
            this.$message({
              message: '请至少选择一个岗位',
              type: 'error'
            })
            return false
          }
        }
        this.updatePostStepBatch(para)
      })
    },
    updatePostStepBatch (para) {
      this.btnLoading = true
      this.$http.post(this.$http.defaults.recruitAPI + `api/recruitBusPostStepBatch/save`, para).then(response => {
        this.btnLoading = false
        if (response.data.success === true) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.backFormVisible = false
          this.$emit('getDetails')
        } else {
          console.log('操作失败:' + response.data.message)
          this.$message({
            message: '操作失败:' + response.data.message,
            type: 'error'
          })
          this.backFormVisible = false
          this.$emit('getDetails')
        }
      }).catch(error => {
        this.btnLoading = false
        console.log(error)
        this.$message({
          message: '操作失败:' + error,
          type: 'error'
        })
      })
    },
    getAnnouncementRemarks () {
      this.$http.get(this.$http.defaults.recruitAPI + `api/recruitBusAnnual/getAnnouncementRemarksByYear?theYear=${this.theYear}`)
        .then(response => {
          if (response.data.success === true) {
            this.announcementRemarks = response.data.result
          } else {
            console.log('获取失败:' + response.data.message)
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        }).catch(error => {
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    }
  }
}
</script>
<style scoped>
  .mytable{
    border-top: 1px solid #74a6cc;
    border-left: 1px solid #74a6cc;
    margin:0 10px 10px;
    width: calc(100% - 20px);
  }
  .mytable th{
    padding: 10px;
    border-right: 1px solid #74a6cc;
    border-bottom: 1px solid #74a6cc;
    vertical-align: top;
    line-height: 150%;
    background: #FAFAFA;
    width:200px;
    text-align:right;
  }
  .mytable td{
    padding: 10px;
    border-right: 1px solid #74a6cc;
    border-bottom: 1px solid #74a6cc;
    vertical-align: top;
    line-height: 150%;
  }
</style>
<style>
#recruitTable .el-table{
  border:1px solid #95B8E7 !important;
}
#recruitTable .el-table td, #recruitTable .el-table th{
  border-right:1px solid #95B8E7 !important;
  border-bottom:1px solid #95B8E7 !important;
}
</style>
